import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AuthModule } from './modules/auth/auth.module';
import { UserModule } from './modules/user/user.module';
import config from './config';
import { DatabaseModule } from './share/database/database.module';
import { SystemModule } from './modules/system/system.module';
import { RedisModule } from './share/redis/redis.module';

import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';

import { JwtAuthGuard } from './modules/auth/guards/jwt-auth.guard';

import { RbacGuard } from './modules/auth/guards/rbac.guard';
import path from 'path';
import { AllExceptionsFilter } from './common/filters/any-exception.filter';
import { TransformInterceptor } from './common/interceptors/transform.interceptor';
// import path from 'path';
console.log(process.env.NODE_ENV, 'process.env.NODE_ENV');
@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      expandVariables: true,
      load: [...Object.values(config)],
      envFilePath: [
        '.env.local',
        `.env.${process.env.NODE_ENV || 'production'}`,
        path.join(__dirname, '.env')
      ]
    }),

    DatabaseModule,
    RedisModule,
    AuthModule,
    UserModule,
    SystemModule
  ],
  controllers: [],
  providers: [
    { provide: APP_FILTER, useClass: AllExceptionsFilter },
    { provide: APP_INTERCEPTOR, useClass: TransformInterceptor },
    { provide: APP_GUARD, useClass: JwtAuthGuard },
    { provide: APP_GUARD, useClass: RbacGuard }
  ]
})
export class AppModule {}
